﻿// JScript source code
var currentPageNumber = 0;
var pageCount = 0;
var flag = true;
$(document).ready(function () {
    setInterval(internalChange, 20000);  //20000  1秒钟一切换。
    initContent();
});

function internalChange() {
    if (flag) {
        var next = currentPageNumber + 1;

        if (next > pageCount)
            next = 1;
        showCategoryPage(next);
    }

}

function showCategoryPage(i) {

    if (currentPageNumber != 0) {
        var pastObject = $($("#page").children()[currentPageNumber - 1]);
        var pastPageNumber = pastObject.attr("data-page")
        pastObject.removeClass("curr").addClass("no_curr").empty().append('<i href="#' + pastPageNumber + '" >' + pastPageNumber + '</i>');
        var needHide = "#pageCategorysIndex" + currentPageNumber;
        $(needHide).addClass("Hide");
    }
    $($("#page").children()[i - 1]).empty().addClass("curr").removeClass("no_curr").append('<i href="#' + i + '" >' + i + '</i>');

    var needShow = "#pageCategorysIndex" + i;
    currentPageNumber = i;
    $(needShow).removeClass("Hide");


}

function initContent() {
    //add by yang used for sys event page control
    $('div.index_pt:first').removeClass('Hide');
    var total = parseInt($('#hfSysEventsPageCount').val());
    $('div#page').html('');
    for (var i = 1; i <= total; i++) {
        $('#page').append('<p class="pageClick no_curr ui-icons" data-page=' + i + '><i href="#' + i + '">' + i + '</i></p>');
    };
    $('p[data-page=1]').removeClass('no_curr').addClass('curr');
    $('input#hfSysName').each(function (index, e) {
        var that = $(e);
        that.prev().attr('id', that.val());
        that.prev().find('a#btnClose').attr('onclick', 'closeDiv("' + that.val() + '")');
    });


    $('i.line_imptant').each(function (index, e) {
        var that = $(e);
        var count = parseInt(that.text());
        var css = that.parent().attr('class').split('_')[0];
        if (count > 0) {
            that.parent().removeAttr('class').addClass(css + "_red ui-icons");
            that.show();
        }
        else {
            that.parent().removeAttr('class').addClass(css + "_green ui-icons");
            that.hide();
        }
    });

    /****control enlarge sys info****/
    $('div#DialogDiv50').each(function (index, e) {
        var that = $(e);
        var title = that.prev().find('div.headpart_title').text().trim() + 'enlarge';
        var opnbtn = that.prev().find('div#btnShow50').attr('onclick', 'ShowDIV("' + title + '")');
        var clobtn = that.find('a#A1').attr('onclick', 'closeDiv("' + title + '")');
        that.attr('id', title);
    });


    //end
    currentPageNumber = 0;
    pageCount = $("#page").children().length;
    $(".pageClick").click(function () {
        var count = $(this).attr("data-page");
        showCategoryPage(parseInt(count));

        $(this).removeClass("no_curr").addClass("curr");
    });
    showCategoryPage(1);
}
//#############################################################################################################################################
//        管理

var ToggleDown = function (showEles, hideEles, addClassEles, removeClassEles) {
    $.each(showEles, function (_i, _e) {
        $(_e).show();
    });

    $.each(hideEles, function (_i, _e) {
        $(_e).hide();
    });

    $.each(addClassEles, function (_i, _e) {
        $(_e).addClass('currB').removeClass('no_currB');
    });

    $.each(removeClassEles, function (_i, _e) {
        $(_e).addClass('no_currB').removeClass('currB');
    });
};

//图表切换
var charIntervalChange = function () {
    $('.down_1,.down_2,.down_3').each(function () {
        $(this).find('.down_slide-controls>.ui-icons.no_currB').click();
    });
};

$(document).ready(function () {
    //左下角
    $("#infoPrevLink").click(function () {
        ToggleDown(['#title_box', '#infoList'], ['#title_box2', '#infoList2'], ['#infoPrevLink'], ['#infoNextLink']);
    });
    $("#infoNextLink").click(function () {
        ToggleDown(['#title_box2', '#infoList2'], ['#title_box', '#infoList'], ['#infoNextLink'], ['#infoPrevLink']);

        //jqplot会依据外围div大小来画图表，所以要在切换到第二张图时再生成图表
        if (!$.trim($('#yearBarChart').html())) {
            renderIncidentYearEffectiveChart();
        }
    });

    //中间
    $("#infoPrevLinkB").click(function () {
        ToggleDown(['#title_boxB', '#infoListB'], ['#title_boxB2', '#infoListB2'], ['#infoPrevLinkB'], ['#infoNextLinkB']);
    });
    $("#infoNextLinkB").click(function () {
        ToggleDown(['#title_boxB2', '#infoListB2'], ['#title_boxB', '#infoListB'], ['#infoNextLinkB'], ['#infoPrevLinkB']);

        if (!$.trim($('#bar').html())) {
            renderDeviceTypePercentChart();
        }
    });

    //右下角
    $("#infoPrevLinkC").click(function () {
        ToggleDown(['#title_boxC', '#infoListC'], ['#title_boxC2', '#infoListC2'], ['#infoPrevLinkC'], ['#infoNextLinkC']);
    });
    $("#infoNextLinkC").click(function () {
        ToggleDown(['#title_boxC2', '#infoListC2'], ['#title_boxC', '#infoListC'], ['#infoNextLinkC'], ['#infoPrevLinkC']);
    });

    //第三部分切换
    setInterval(charIntervalChange, 10000);
});
//#############################################################################################################################################

$(document).ready(function () {
    //         全部分类
    //Default Action 
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("c").show(); //Activate first tab 
    $(".tab_content:first").show(); //Show first tab content 
    //On Click Event 
    $("ul.tabs li").click(function () {
        $("ul.tabs li").removeClass("c"); //Remove any "active" class 
        $(this).addClass("c"); //Add "active" class to selected tab 
        $(".tab_content").hide(); //Hide all tab content 
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content 
        $(activeTab).fadeIn(); //Fade in the active content 
        return false;
    });
});

//#############################################################################################################################################
//遮罩层显示
function ShowDIV(thisObjID) {
    $("#BgDiv").css({ display: "block", height: $(document).height() });
    var yscroll = document.documentElement.scrollTop;
    $("[id='" + thisObjID + "']").css("top", "100px");
    $("[id='" + thisObjID + "']").css("display", "block");
    //$("#" + thisObjID).css("top", "100px");
    //$("#" + thisObjID).css("display", "block");
    document.documentElement.scrollTop = 0;
    flag = false;
}

function closeDiv(thisObjID) {
    $("[id='" + thisObjID + "']").css("display", "none");
    var activeDialogCount = $('.DialogDiv:visible').length;

    if (activeDialogCount == 0) {
        $("#BgDiv").css("display", "none");

        //$("#" + thisObjID).css("display", "none");
        flag = true;
    }
}


//#############################################################################################################################################
//画图表

///饼状图
var drawPieChart = function (data, container, rendererOptions, legendOption) {

    var plot_effective = $.jqplot(container, [data], {
        seriesDefaults: {
            renderer: $.jqplot.PieRenderer,
            rendererOptions: $.extend({}, {
                diameter: 160,
                showDataLabels: true
            }, rendererOptions),
            trendline: {
                show: true
            }
        },
        grid: {
            background: '#112836',
            borderWidth: 0,
            shadow: false
        },
        legend: $.extend({},
        {
            show: true,
            marginRight: '55px',
            marginTop: 10,
            background: '#112836',
            border: '0px'
        }, legendOption)
    });
};

///柱状图
var drawBarChart = function (data, container, rendererOptions, legendOption) {

    var labels = [];
    $.each(data, function (_i, _d) {
        labels.push({ label: _d[0] });
    });

    var plot_effective_bar = $.jqplot(container, [data], {
        seriesDefaults: {
            renderer: $.jqplot.BarRenderer,
            rendererOptions: $.extend({}, {
                barMargin: 5,
                varyBarColor: true
            }, rendererOptions)
        },
        grid: {
            background: '#112836'
        },
        series: labels,
        legend: $.extend({}, {
            //renderer: $.jqplot.EnhancedLegendRenderer,
            //labels: ['s1', 's2', 's3'],
            show: false,
            location: 's',
            placement: 'outside',
            marginBottom: 0,
            marginRight: 0,
            background: '#112836',
            border: '0px',
            shrinkGrid: true,
            rendererOptions: {
                numberRows: 1
            }
        }, legendOption),

        axesDefaults: {
            tickRenderer: $.jqplot.CanvasAxisTickRenderer,
            tickOptions: {
                fontSize: '8pt',
                textColor: '#fff'
            }
        },
        axes: {
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                tickOptions: {
                    showGridline: false,
                    angle: -30,
                    show: true
                }
            }
        }
    });
};

//#############################################################################################################################################
//中间系统名切换
var slideSysName = function (leftOrRight) {
    var unitDistance = 156,
        container = $('.tab_area_inner'),
        containerWidth = container.width(),
        wrapperWidth = $('.tab_area_wrapper').width();

    var leftmove = container.css('left').replace('px', '') * 1;
    if (leftOrRight == "left") {
        leftmove = Math.max(wrapperWidth - containerWidth, leftmove - unitDistance);
    } else {
        leftmove = Math.min(0, leftmove + unitDistance);
    }

    container.css({ left: leftmove + 'px' });

}